<template>
  <div id="referralInvitation">
    <h1 class="con-right-title">转介绍邀请记录</h1>
    <topSearch
      :formInline="formInline"
      @toSearch="toSearch"
      :activityAll="activityAll"
    ></topSearch>
    <div class="table-conBtn">
      <el-button
        class="keepRight"
        type="success"
        @click="dialogFormVisibleShow"
      >
        导出Excel
      </el-button>
      <span
        >此活动参与人数:
        <template>
          <span v-if="activityStatistical.joinCount == null">0 人</span>
          <span v-else>{{ activityStatistical.joinCount }} 人</span>
        </template>
      </span>
      <span
        >此活动入量人数:
        <template>
          <span v-if="activityStatistical.flowCount == null">0 人</span>
          <span v-else>{{ activityStatistical.flowCount }} 人</span>
        </template>
      </span>
      <span
        >此活动开通试学课人数:
        <template>
          <span v-if="activityStatistical.trialCount == null">0 人</span>
          <span v-else>{{ activityStatistical.trialCount }} 人</span>
        </template>
      </span>
      <span
        >此活动成单人数:
        <template>
          <span v-if="activityStatistical.orderCount == null">0 人</span>
          <span v-else>{{ activityStatistical.orderCount }} 人</span>
        </template>
      </span>
      <span
        >此活动提现金额:
        <template>
          <span v-if="activityStatistical.withdrawalAmount == null"> 0元</span>
          <span v-else>{{ activityStatistical.withdrawalAmount }} 元</span>
        </template>
      </span>
      <freshCom @searchList="searchList"></freshCom>
    </div>
    <!-- 表格 -->
    <el-table :data="tableData" stripe max-height="490" ref="table">
      <el-table-column type="index" label="序号" width="50" align="center">
        <template slot-scope="scope">
          {{
            scope.$index
              | filterPage(searchParams.pageNum, searchParams.pageSize)
          }}
        </template>
      </el-table-column>
      <el-table-column label="邀请人" min-width="150" align="center">
        <template v-slot="{ row }">
          {{ row.adverUserName }}
        </template>
      </el-table-column>
      <el-table-column label="邀请人大鹏号" min-width="100" align="center">
        <template v-slot="{ row }">
          {{ row.adverDpAccount }}
        </template>
      </el-table-column>
      <el-table-column label="邀请人手机号" min-width="100" align="center">
        <template v-slot="{ row }">
          {{ row.adverPhone }}
        </template>
      </el-table-column>
      <el-table-column label="被邀请人" min-width="100" align="center">
        <template v-slot="{ row }">
          {{ row.userName }}
        </template>
      </el-table-column>
      <el-table-column label="被邀请人时间" min-width="150" align="center">
        <template v-slot="{ row }">
          {{ row.createTime }}
        </template>
      </el-table-column>
      <el-table-column min-width="120" label="被邀请人大鹏号" align="center">
        <template v-slot="{ row }">
          {{ row.dpAccount }}
        </template>
      </el-table-column>
      <el-table-column min-width="120" label="被邀请人手机号" align="center">
        <template v-slot="{ row }">
          {{ row.phone }}
        </template>
      </el-table-column>

      <el-table-column label="试学课时间" min-width="150" align="center">
        <template v-slot="{ row }">
          {{ row.trialStatus }}
        </template>
      </el-table-column>
      <el-table-column label="当前状态" min-width="100" align="center">
        <template v-slot="{ row }">
          <span v-if="row.trialType == '0'">注册未领课</span>
          <span v-if="row.trialType == '1'">已领课</span>
        </template>
      </el-table-column>
      <el-table-column label="活动名称" min-width="100" align="center">
        <template v-slot="{ row }">
          {{ row.activityName }}
        </template>
      </el-table-column>
      <el-table-column label="活动状态" min-width="100" align="center">
        <template v-slot="{ row }">
          <span v-if="row.activityStatus == 'NOT_STARTED'">未开始</span>
          <span v-if="row.activityStatus == 'ONGOING'">进行中</span>
          <span v-if="row.activityStatus == 'OVER'">已结束</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="200" align="center">
        <template v-slot="{ row }">
          <div class="action-wrap">
            <el-button type="text" @click="dialogTableVisibleShow(row)"
              >查看详情</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pageCom
      :searchParams="searchParams"
      @searchList="searchList"
      :total="total"
    ></pageCom>
    <!-- 查看详情dialog -->
    <chooseBounced
      :show.sync="dialogTableVisible"
      :gridData="gridData"
      :userName="userName"
    />
    <!-- 导出表单弹窗 -->
    <exportDialog :exportShow.sync="exportShow" />
  </div>
</template>

<script>
import topSearch from './topSearch'
import chooseBounced from './chooseBounced'
import exportDialog from './exportDialog'
// api
import {
  getAllActivity,
  getwithdrawList,
  getStatisticsList,
  getInviteeList
} from '@/api/invitedRecord/index'
export default {
  name: 'referralInvitation',
  components: {
    topSearch,
    chooseBounced,
    exportDialog
  },
  data() {
    return {
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10 // 页面显示条数
      },
      total: 0,
      // 查看详情
      dialogTableVisible: false,
      // 导出弹窗的显示or隐藏
      exportShow: false,
      // 全部活动
      activityAll: [],
      // 写死一个活动id 不传报400 404
      activityId: '623bd97831b8ec1060003012',
      // 搜索条件
      formInline: {
        // time: [],
        activityId: '', //活动id
        dpAccount: '', // 大鹏号 or 手机号
        startFlowTime: '', // 开始时间
        endFlowTime: '' // 结束时间
        // status: '' // 状态
      },
      // 表格数据
      tableData: [],
      // 活动统计
      activityStatistical: {},
      // 查看详情
      gridData: [],
      // 邀请人名字
      userName: ''
    }
  },
  methods: {
    // 点击查看
    dialogTableVisibleShow(row) {
      // 查看详情
      let params = { activityId: row.activityId, dpAccount: row.adverDpAccount }
      getInviteeList(
        params,
        (res) => {
          this.userName = row.adverUserName
          this.gridData = res
        },
        (err) => {
          console.log(err)
        }
      )
      this.dialogTableVisible = true
    },
    // 点击导出
    dialogFormVisibleShow() {
      this.exportShow = true
    },
    /* 获取列表 */
    searchList() {
      if (this.formInline.activityId == '') {
        this.formInline.activityId = this.activityId
      }
      let params = { ...this.searchParams, ...this.formInline }
      getwithdrawList(
        params,
        (res) => {
          if (res.rows) {
            this.tableData = res.rows
            this.total = res.total
          }
        },
        (err) => {
          console.log(err)
        }
      )
    },
    // 查询按钮
    toSearch(e) {
      this.searchParams.pageNum = 1
      if (
        this.formInline.activityId == '' ||
        this.formInline.activityId == undefined
      ) {
        this.formInline.activityId = this.activityId
      }
      this.searchList()
      this.getAllActivity(e)
    },
    /* 换页 */
    changePage(page) {
      this.searchParams.pageNum = page
      this.searchList()
    },
    // 获取全部活动
    getAllActivity(e) {
      let params = ''
      getAllActivity(
        params,
        (res) => {
          this.activityAll = res
          this.activityId = e
          // 获取统计
          this.getStatistical()
        },
        (err) => {
          console.log(err)
        }
      )
    },
    // 统计接口
    getStatistical() {
      if (this.formInline.activityId == '') {
        this.formInline.activityId = this.activityId
      }
      let params = { activityId: this.formInline.activityId }
      getStatisticsList(
        params,
        (res) => {
          this.activityStatistical = res
        },
        (err) => {
          console.log(err)
        }
      )
    },
    refreshList() {
      this.searchParams.pageNum = 1
      this.searchList()
    }
  },
  created() {
    this.searchList()
    if (this.formInline.activityId == '') {
      this.formInline.activityId = '6209f80ea40dfb3e7ecdae01'
    }
    // 获取活动名称
    this.getAllActivity()
  },
  watch: {},
  mounted() {},
  computed: {}
}
</script>

<style lang="less" scoped>
#referralInvitation {
  .table-conBtn {
    font-size: 16px;
    color: #0d1636;
    span {
      margin: 0 10px;
    }
  }
  .keepRight {
    margin-right: 20px;
    border-radius: 14px;
  }
}
</style>
